package com.pioneer.swing.ui;

import com.pioneer.beans.Key;
import com.pioneer.beans.Keyed;
import com.pioneer.beans.ContainerKey;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.Box;
import javax.swing.BoxLayout;

/**
 * Title:        Pioneer Metals Application
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Pioneer Metals
 * @author Gary Chen
 * @version 1.0
 */

public class JobEntryFrame extends JInternalFrame {
	public JTable itemsTable;
	
	public JButton deleteButton;
	public JButton contactEditorButton;
	//public JButton saveJobButton;
	

	public JTextField quoteNumTextField=new JTextField(7);
	public JTextField jobNameTextField=new JTextField(15);
	public JTextField jobDateTextField=new JTextField(7);
	public JTextField shipDateTextField=new JTextField(7);
	public JTextField expirationDateTextField=new JTextField(7);
	public JTextField addressTextField=new JTextField(35);
	public JTextField cityTextField=new JTextField(20);
	public JTextField stateTextField=new JTextField(3);
	public JTextField zipTextField=new JTextField(10);
	public JTextField numOfUnitsTextField=new JTextField(5);
	public JComboBox typeComboBox=new JComboBox();
	public JComboBox regSalesManComboBox=new JComboBox();
	public String selectedRegSalesMan;
	
	public JTextField termsTextField=new JTextField(25);
	public JTextField notesTextField=new JTextField(50);
	public boolean comboBoxInit;		
	public JComboBox statusComboBox=new JComboBox();
	
	public JComboBox supplierNameComboBox = new JComboBox();
	public String selectedSupplier;
	public JTextField supplierContactTextField=new JTextField(15);
	public JTextField supplierAddressTextField=new JTextField(30);
	public JTextField supplierCityTextField=new JTextField(20);
	public JTextField supplierStateTextField=new JTextField(3);
	public JTextField supplierZipTextField=new JTextField(10);
	public JTextField supplierPhoneNoTextField=new JTextField(14);
	public JTextField supplierFaxNoTextField=new JTextField(14);
	
	public JComboBox contractorNameComboBox=new JComboBox();
	public String selectedContractor;
	public JTextField contractorContactTextField=new JTextField(15);
	public JTextField contractorAddressTextField=new JTextField(30);
	public JTextField contractorCityTextField=new JTextField(20);
	public JTextField contractorStateTextField=new JTextField(3);
	public JTextField contractorZipTextField=new JTextField(10);
	public JTextField contractorPhoneNoTextField=new JTextField(14);
	public JTextField contractorFaxNoTextField=new JTextField(14);
	
	public JComboBox salesRepComboBox=new JComboBox();
	public String selectedSalesRep;
	public JTextField salesRepContactTextField=new JTextField(15);
	public JTextField salesRepAddressTextField=new JTextField(30);
	public JTextField salesRepCityTextField=new JTextField(20);
	public JTextField salesRepStateTextField=new JTextField(3);
	public JTextField salesRepZipTextField=new JTextField(10);
	public JTextField salesRepPhoneNoTextField=new JTextField(14);
	public JTextField salesRepFaxNoTextField=new JTextField(14);
	
	public JComboBox builderNameComboBox=new JComboBox();
	public String selectedBuilder;
	public JTextField builderContactTextField=new JTextField(15);
	public JTextField builderAddressTextField=new JTextField(30);
	public JTextField builderCityTextField=new JTextField(20);
	public JTextField builderStateTextField=new JTextField(3);
	public JTextField builderZipTextField=new JTextField(10);
	public JTextField builderPhoneNoTextField=new JTextField(14);
	public JTextField builderFaxNoTextField=new JTextField(14);
	
    public JobEntryFrame() {
    	super(UIConstants.TITLE_JOB_ENTRY,true,true);
		this.setName(UIConstants.TITLE_JOB_ENTRY);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		disableComponents();

    	JPanel mainPanel=new JPanel(new BorderLayout());
		mainPanel.setBorder(BorderFactory.createEmptyBorder(
                                        15, //top
                                        15, //left
                                        5, //bottom
                                        15) //right
										);
		JPanel centerPanel=new JPanel();
		centerPanel.setLayout(new BorderLayout());
		JPanel headerPanel=new JPanel(new GridLayout(3,1));		
		JPanel generalPanel = new JPanel();
		generalPanel.setLayout(new GridLayout(4,1));
		generalPanel.setBorder(BorderFactory.createTitledBorder("General Info"));
		JPanel general1 = new JPanel();
		general1.add(new JLabel("Quote#: "));
		general1.add(quoteNumTextField);
		//general1.add(new JLabel("Sales Rep: "));
		//general1.add(salesRepComboBox);
		general1.add(new JLabel("Date: "));
		general1.add(jobDateTextField);
		general1.add(new JLabel("Ship Date: "));
		general1.add(shipDateTextField);		
		general1.add(new JLabel("Expir. Date: "));
		general1.add(expirationDateTextField);		
		generalPanel.add(general1);
		JPanel general2 = new JPanel();
		general2.add(new JLabel("Job Name: "));
		general2.add(jobNameTextField);
		general2.add(new JLabel("Status: "));
		general2.add(statusComboBox);
		general2.add(new JLabel("Units: "));
		general2.add(numOfUnitsTextField);
		general2.add(new JLabel("Type: "));	
		general2.add(typeComboBox);
		general2.add(new JLabel("Regional S.M.: "));
		general2.add(regSalesManComboBox);
		generalPanel.add(general2);
		JPanel general3 = new JPanel();
		general3.add(new JLabel("Address: "));
		general3.add(addressTextField);
		general3.add(new JLabel("City: "));
		general3.add(cityTextField);
		general3.add(new JLabel("State: "));
		general3.add(stateTextField);
		general3.add(new JLabel("Zip: "));
		general3.add(zipTextField);
		generalPanel.add(general3);
		JPanel general4 = new JPanel();
		general4.add(new JLabel("Terms: "));
		general4.add(termsTextField);
		general4.add(new JLabel("Notes: "));
		general4.add(notesTextField);
		generalPanel.add(general4);
		headerPanel.add(generalPanel);		

		JPanel contactPanel1 = new JPanel();
		contactPanel1.setLayout(new GridLayout(1,2));
		
		JPanel salesRepPanel = new JPanel();
		salesRepPanel.setBorder(BorderFactory.createTitledBorder("Sales Rep Info"));
		salesRepPanel.setLayout(new GridLayout(4,1));
		JPanel salesRep1 = new JPanel();
		salesRep1.add(new JLabel("Name: "));
		salesRep1.add(salesRepComboBox);
		salesRep1.add(new JLabel("Contact: "));
		salesRep1.add(salesRepContactTextField);
		salesRepPanel.add(salesRep1);
		JPanel salesRep2 = new JPanel();
		salesRep2.add(new JLabel("Phone Number: "));
		salesRep2.add(salesRepPhoneNoTextField);
		salesRep2.add(new JLabel("Fax Number: "));
		salesRep2.add(salesRepFaxNoTextField);
		salesRepPanel.add(salesRep2);
		JPanel salesRep3 = new JPanel();
		salesRep3.add(new JLabel("Address: "));
		salesRep3.add(salesRepAddressTextField);
		salesRepPanel.add(salesRep3);
		JPanel salesRep4 = new JPanel();
		salesRep4.add(new JLabel("City: "));
		salesRep4.add(salesRepCityTextField);
		salesRep4.add(new JLabel("State: "));
		salesRep4.add(salesRepStateTextField);
		salesRep4.add(new JLabel("Zip: "));
		salesRep4.add(salesRepZipTextField);
		salesRepPanel.add(salesRep4);
		contactPanel1.add(salesRepPanel);
		
		JPanel builderPanel = new JPanel();
		builderPanel.setBorder(BorderFactory.createTitledBorder("Builder Info"));
		builderPanel.setLayout(new GridLayout(4,1));
		JPanel builder1 = new JPanel();
		builder1.add(new JLabel("Name: "));
		builder1.add(builderNameComboBox);
		builder1.add(new JLabel("Contact: "));
		builder1.add(builderContactTextField);
		builderPanel.add(builder1);
		JPanel builder2 = new JPanel();
		builder2.add(new JLabel("Phone Number: "));
		builder2.add(builderPhoneNoTextField);
		builder2.add(new JLabel("Fax Number: "));
		builder2.add(builderFaxNoTextField);
		builderPanel.add(builder2);
		JPanel builder3 = new JPanel();
		builder3.add(new JLabel("Address: "));
		builder3.add(builderAddressTextField);
		builderPanel.add(builder3);
		JPanel builder4 = new JPanel();
		builder4.add(new JLabel("City: "));
		builder4.add(builderCityTextField);
		builder4.add(new JLabel("State: "));
		builder4.add(builderStateTextField);
		builder4.add(new JLabel("Zip: "));
		builder4.add(builderZipTextField);
		builderPanel.add(builder4);
		contactPanel1.add(builderPanel);
		headerPanel.add(contactPanel1);
				
		JPanel contactPanel2 = new JPanel();
		contactPanel2.setLayout(new GridLayout(1,2));
		
		JPanel contractorPanel = new JPanel();
		contractorPanel.setBorder(BorderFactory.createTitledBorder("Contractor Info"));
		contractorPanel.setLayout(new GridLayout(4,1));
		JPanel contractor1 = new JPanel();
		contractor1.add(new JLabel("Name: "));
		contractor1.add(contractorNameComboBox);
		contractor1.add(new JLabel("Contact: "));
		contractor1.add(contractorContactTextField);
		contractorPanel.add(contractor1);
		JPanel contractor2 = new JPanel();
		contractor2.add(new JLabel("Phone Number: "));
		contractor2.add(contractorPhoneNoTextField);
		contractor2.add(new JLabel("Fax Number: "));
		contractor2.add(contractorFaxNoTextField);
		contractorPanel.add(contractor2);
		JPanel contractor3 = new JPanel();
		contractor3.add(new JLabel("Address: "));
		contractor3.add(contractorAddressTextField);
		contractorPanel.add(contractor3);
		JPanel contractor4 = new JPanel();
		contractor4.add(new JLabel("City: "));
		contractor4.add(contractorCityTextField);
		contractor4.add(new JLabel("State: "));
		contractor4.add(contractorStateTextField);
		contractor4.add(new JLabel("Zip: "));
		contractor4.add(contractorZipTextField);
		contractorPanel.add(contractor4);
		contactPanel2.add(contractorPanel);
		
		JPanel supplierPanel = new JPanel();
		supplierPanel.setBorder(BorderFactory.createTitledBorder("Supplier Info"));
		supplierPanel.setLayout(new GridLayout(4,1));
		JPanel supplier1 = new JPanel();
		supplier1.add(new JLabel("Name: "));
		supplier1.add(supplierNameComboBox);
		supplier1.add(new JLabel("Contact: "));
		supplier1.add(supplierContactTextField);
		supplierPanel.add(supplier1);
		JPanel supplier2 = new JPanel();
		supplier2.add(new JLabel("Phone Number: "));
		supplier2.add(supplierPhoneNoTextField);
		supplier2.add(new JLabel("Fax Number: "));
		supplier2.add(supplierFaxNoTextField);
		supplierPanel.add(supplier2);
		JPanel supplier3 = new JPanel();
		supplier3.add(new JLabel("Address: "));
		supplier3.add(supplierAddressTextField);
		supplierPanel.add(supplier3);
		JPanel supplier4 = new JPanel();
		supplier4.add(new JLabel("City: "));
		supplier4.add(supplierCityTextField);
		supplier4.add(new JLabel("State: "));
		supplier4.add(supplierStateTextField);
		supplier4.add(new JLabel("Zip: "));
		supplier4.add(supplierZipTextField);
		supplierPanel.add(supplier4);
		contactPanel2.add(supplierPanel);		
		headerPanel.add(contactPanel2);
		
		centerPanel.add(headerPanel,BorderLayout.NORTH);


		// Table of containers here
		
		itemsTable=new JTable();		
		//itemsTable.setFocusable(false);
		JScrollPane scrollPane=new JScrollPane(itemsTable);
		centerPanel.add(scrollPane,BorderLayout.CENTER);
		
		// add the footer area. consists of a button panel on the left and a totals panel on the right

		JPanel footerPanel=new JPanel();
		JPanel buttonPanel=new JPanel();
		buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
		//deleteButton=new TwoKeyedButton(UIConstants.COMMAND_DELETE_ITEM);
		//saveJobButton=new JButton(UIConstants.COMMAND_SAVE_JOB_BUTTON);
		//buttonPanel.add(saveJobButton);
		deleteButton=new JButton(UIConstants.COMMAND_DELETE_ITEM);
		buttonPanel.add(deleteButton);
		contactEditorButton = new JButton(UIConstants.COMMAND_OPEN_JOBS_CONTACTEDITOR);
		buttonPanel.add(contactEditorButton);
		footerPanel.add(buttonPanel);

		centerPanel.add(footerPanel,BorderLayout.SOUTH);	
		mainPanel.add(centerPanel);
	   	this.getContentPane().add(mainPanel,BorderLayout.CENTER);
    }



	private String getSelectedJobNum()
	{
		return quoteNumTextField.getText();
	}

	private String getSelectedId()
	{
		int row=itemsTable.getSelectedRow();
		if (row>-1) {
			return itemsTable.getModel().getValueAt(row,0).toString();
		} else {
			// should never happen
			return null;
		}
	}

    public static void main(String[] args) {


        ManifestEntryFrame mainMenuFrame = new ManifestEntryFrame();
    }
	
	private void disableTextField(JTextField textField) {
		textField.setEditable(false);
		textField.setFocusable(false);
	}
	
	private void disableComponents() {
		disableTextField(supplierAddressTextField);
		disableTextField(supplierCityTextField);
		disableTextField(supplierStateTextField);
		disableTextField(supplierZipTextField);
		disableTextField(supplierPhoneNoTextField);
		disableTextField(supplierFaxNoTextField);
		
		disableTextField(contractorAddressTextField);
		disableTextField(contractorCityTextField);
		disableTextField(contractorStateTextField);
		disableTextField(contractorZipTextField);
		disableTextField(contractorPhoneNoTextField);
		disableTextField(contractorFaxNoTextField);
		
		disableTextField(salesRepAddressTextField);
		disableTextField(salesRepCityTextField);
		disableTextField(salesRepStateTextField);
		disableTextField(salesRepZipTextField);
		disableTextField(salesRepPhoneNoTextField);
		disableTextField(salesRepFaxNoTextField);
		
		disableTextField(builderAddressTextField);
		disableTextField(builderCityTextField);
		disableTextField(builderStateTextField);
		disableTextField(builderZipTextField);
		disableTextField(builderPhoneNoTextField);
		disableTextField(builderFaxNoTextField);
		
		
		
	}


}
